package com.sporadic.backstage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sporadic.backstage.entity.DiningTable;
import com.sporadic.backstage.service.DiningTableService;
import feign.Body;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin(origins = {"http://localhost:8080"}, methods = {RequestMethod.GET, RequestMethod.POST}, allowCredentials = "true")
@Controller
public class DiningTableController {

    @Autowired
    private DiningTableService diningTableService;


    /**
     * 分页查询房台列表
     * @param map  查询条件 ：根据区域  page 分页条件（页面大小,页面起始位置）
     * @return 返回查询出来的分页信息
     */
    @PostMapping("/findDiningTableByPage")
    @ResponseBody
    public IPage<DiningTable> findDiningTableByPage(@RequestBody Map<String,Object> map){
        Page<DiningTable> page=new Page<>();
        page.setCurrent((Integer) map.get("current"));
        page.setSize((Integer) map.get("pageSize"));
        return diningTableService.findDiningTableByPage(page,map);
    }

    /**
     * 删除房台
     *
     * @param diningTableId 房台ID
     * @return 删除结果 受影响的行数
     */
    @GetMapping("/delDiningTableById")
    @ResponseBody
    public int delDiningTableById(@RequestParam(value = "diningTableId",required = false) Integer diningTableId,@RequestParam(value = "diningTableAreaId",required = false)Integer diningTableAreaId){
        return diningTableService.delDiningTableById(diningTableId,diningTableAreaId);
    }


    /**
     * 修改房台信息
     *
     * @param diningTable 要修改的房台信息
     * @return 修改结果 受影响的行数
     */
    @PostMapping("/modifyDiningTable")
    @ResponseBody
    public int modifyDiningTable(@RequestBody DiningTable diningTable){
        return diningTableService.modifyDiningTable(diningTable);
    }


    /**
     * 批量添加房台
     * @param diningTables 房台信息集合  可单独添加
     * @return 返回添加结果 受影响的行数
     */
    @RequestMapping("/batchInsertDiningTable")
    @ResponseBody
    public int batchInsertDiningTable(@RequestBody List<DiningTable> diningTables){
        return diningTableService.batchInsertDiningTable(diningTables);
    }




}
